#ifndef MSGBASE_H
#define MSGBASE_H
#include <string>
#include <QVariant>
#include <QMetaType>
#include <QDebug>
#include "Main/constant.h"


class MsgBase
{
public:
    std::string ToString()
    {
        std::string sEncode = GESS_FLD_SEPERATOR;

    //    MAP_KEYVAL::iterator it;
        for(auto it = m_mapParameters.begin();it!=m_mapParameters.end();++it)
        {
            sEncode += it->first;
            sEncode += "=";
            sEncode += it->second;
            sEncode += GESS_FLD_SEPERATOR;
        }
        return sEncode;
    }

    void AddPara(const std::string sKey, QVariant v)
    {
//        qDebug()<<"QVariant 类型转换:"<<v.type();
        if (v.type() == (QMetaType::Int))
        {
            m_mapParameters[sKey] = std::to_string(v.toInt());
        }
        else if (v.type() == (QMetaType::Double))
        {
            m_mapParameters[sKey] = std::to_string(v.toDouble());
        }
        else if (v.type() == (QMetaType::QString))
        {
            m_mapParameters[sKey] = v.toString().toLocal8Bit().toStdString();//toStdString();
        }
        else if (v.type() == (QMetaType::QChar))
        {
            m_mapParameters[sKey] = QString(v.toChar()).toStdString();
        }
        else
        {
            qDebug()<<"QVariant 未增加类型转换:"<<v.type();
        }
    }
protected:
    typedef std::map<std::string,std::string> MAP_KEYVAL;
    MAP_KEYVAL m_mapParameters;
};

#endif // MSGBASE_H



